package logic

import (
	"context"
	"yk/models/mysql"

	"yk/ykrpc/internal/svc"
	"yk/ykrpc/ykrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type YkAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewYkAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *YkAddLogic {
	return &YkAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *YkAddLogic) YkAdd(in *ykrpc.YkAddRequest) (*ykrpc.YkAddResponse, error) {
	// todo: add your logic here and delete this line
	phone := mysql.Phone{
		Name:    in.Name,
		Num:     int(in.Num),
		Address: in.Address,
	}
	mysql.DB.Create(&phone)
	return &ykrpc.YkAddResponse{
		Id: int64(phone.ID),
	}, nil
}
